/**
 * DJ传奇公用JS
 * @author kevinE kevin-e-e@foxmail.com
 * @version 1.2 2022-1-27 09:57:47
 */

const public = true;

// 后端接口appKey
const APPKEY = "5ded368547b86b331";
// 云片appId
const YP_APPId = "80fe987ccea24085bc07bd8a00587d42";
// 后端请求域
let hns = location.hostname.split(".");
let hn = "" + hns[0] + "." + hns[1];
let locals = ["192.168", "127.0"];
const DOMAIN = ~locals.indexOf(hn)
  ? "http://rent.qunx.cc:56"
  : "http://api.hfksh.cn:56";
// const DOMAIN = "http://api.hfksh.cn:56";

// 图片资源服务器 api.hfksh.cn:56
// const IMG_DOMAIN = "http://rent.qunx.cc:56/storage/";
const IMG_DOMAIN2 = "http://rent.hfksh.cn:56/storage/";
const IMG_DOMAIN = "http://oss.hfksh.cn:56/storage/";
// APP下载服务器
const DOWNLOAD_DOMAIN = "http://download.tnlyipr.cn";
// 二维码短链
const SHORT_URL = "http://rent.hfksh.cn:56/qr/";
// cookie前缀
const PREFIX = "make";
// 登录页面
const LOGIN_PAGE = "login.html";
// 游戏ID
const GAME_ID = 1508;

const GAME_ID2 = 1508;

// 客服配置
const SERVICE = {
  link: "http://kf.taoli.name/index/index/home?visiter_id=&visiter_name=&avatar=&business_id=1&groupid=0&special=",
  seat: [1],
};

// 接口地址
const API_PATH = {
  // 检查版本信息
  CHECK_VERSION: DOMAIN + "/home/index/checkVersion",
  // 短信验证码接口url
  SMS_CODE: DOMAIN + "/home/index/sendSms",
  // 注册接口路径
  REGISTER: DOMAIN + "/home/index/reg",
  // 登录接口路径
  LOGIN: DOMAIN + "/home/index/login",
  // 找回/重置密码
  RESET_PWD: DOMAIN + "/home/index/resetPwd",
  // 绑定支付宝账号
  BIND_ALIPAY: DOMAIN + "/home/user/bindAli",
  // 获取用户信息接口url
  USER_INFO: DOMAIN + "/home/user/getUserInfo",
  // 直推好友
  DIRECT_FRIEND: DOMAIN + "/home/user/getOneUser",
  // 间推好友
  INDIRECT_FRIEND: DOMAIN + "/home/user/getTwoUser",
  // 提现  money,(需要头部传参)， Post
  CASH: DOMAIN + "/home/user/cash",
  // 零钱记录
  WITHDRAWAL_RECORD: DOMAIN + "/home/user/balanceDetailList",
  //游戏等级列表
  GAME_LEVEL_LIST: DOMAIN + "/home/user/getGameLevelList",
  //游戏等级领奖
  GAME_UPGRADE: DOMAIN + "/home/user/gameUpgradeGetGoldCoin",
  //好友列表
  GET_TEAME_LIST: DOMAIN + "/home/user/getTeamList",
  //用户升级
  UP_LEVEL: DOMAIN + "/home/user/upLevel",
  //领取游戏等级列表
  GAME_UPGRADE_REWARD: DOMAIN + "/home/game/gameUpgradeLvReward",
  // 游戏等级奖励：(需要头部传参)  Get
  GET_GMLIST: DOMAIN + "/home/game/getGmLvList",
  // 余额明细：page,(需要头部传参)  Get
  MONEY_DETAIL_LIST: DOMAIN + "/home/user/moneyDetailList",
  // 签到列表
  SIGN_LIST: DOMAIN + "/home/game/sign_list",
  //签到
  TO_SIGN: DOMAIN + "/home/game/to_sign",
  // 地段列表
  JOB_LIST: DOMAIN + "/home/job/list",
  // 地段合成
  JOB_SYNTHESIS: DOMAIN + "/home/job/synthesis",
  // 使用地段
  JOB_USE_IT: DOMAIN + "/home/job/use_it",
  // 首页建筑列表
  GET_JZ_LIST: DOMAIN + "/home/index/getJzList",
  // 购买建筑 确认建造
  BUY_HOUSE: DOMAIN + "/home/index/buyHouse",
  // 科技列表
  TYPE_LIST: DOMAIN + "/home/type/list",
  // 升级科技
  UP_TECHNOLOGY: DOMAIN + "/home/type/up_technology",
  // 音乐喷泉
  GET_CONGIG: DOMAIN + "/home/index/getConfig",
  // 转赠 get
  ZS_DQ: DOMAIN + "/home/user/zs_dq",
  // 转赠 手续费
  TO_ZS: DOMAIN + "/home/user/to_zs",
  // 检索用户
  SEARCH_USER: DOMAIN + "/home/user/search_user",
  // 任务列表 任务类型 1新手任务 2房间任务 3周常任务 4推广任务
  TASK_LIST: DOMAIN + "/home/task/index",
  // 人才列表
  SHOP_LIST: DOMAIN + "/home/shop/list",
  // 人才详情
  SHOP_DETAIL: DOMAIN + "/home/shop/detail",
  // 人才招募和进阶
  SYNTHESIS_UP: DOMAIN + "/home/shop/synthesis_up",
  // GET人才任命列表
  USE_LIST: DOMAIN + "/home/shop/use_list",
  // 人才任命 post
  TO_USE: DOMAIN + "/home/shop/to_use",
  // 人才卸任 post
  TO_OUT: DOMAIN + "/home/shop/to_out",
  // 离线时间接口
  LEAVE_TIME: DOMAIN + "/home/income/leave_time",
  // 重连获取离线奖励接口
  REG_TIME: DOMAIN + "/home/income/reg_time",
  // 金币兑换列表  get
  GOLD_LIST: DOMAIN + "/home/gold/list",
  // 金币兑换 post
  GOLD_EXCHANGE: DOMAIN + "/home/gold/exchange",
  // 市场分类列表
  PROP_LIST: DOMAIN + "/home/house/prop_list",
  // 发布求购/出售  1求购 2出售  money num cid
  HOUSE_SAVE: DOMAIN + "/home/house/save",
  // 取消上架道具
  HOUSE_CANCEL: DOMAIN + "/home/house/cancel",
  // 我的求购/出售列表  1 求购 2出售
  HOUSE_LIST: DOMAIN + "/home/house/list",
  // 市场列表 wp_type  0 1 2 3 4 5
  HOUSE_SHOP_LIST: DOMAIN + "/home/house/shop_list",
  // 出售/购买接口
  HOUSE_ORDER_ADD: DOMAIN + "/home/house_order/add",
  // 交易记录
  HOUSE_ORDER_RECORD: DOMAIN + "/home/house_order/record",
  // 靓号列表
  BEAUTIFUL_ACCOUNT_INDEX: DOMAIN + "/home/beautiful_account/index",
  // 购买靓号
  BEAUTIFUL_ACCOUNT_BUY: DOMAIN + "/home/beautiful_account/buy",
  // 领取房产收益
  GET_INCOME: DOMAIN + "/home/income/get_income",
  // 招募详情页
  RECRUIT_RECORD_INDEX: DOMAIN + "/home/recruit_record/index",
  // 招募租客  h_id房产id  num招募数量
  RECRUIT_RECORD_TO_DO: DOMAIN + "/home/recruit_record/to_do",
  // 扩建房产
  INDEX_UPHOUSE: DOMAIN + "/home/index/upHouse",
  // 招募所需金额
  ZZ_MONEY: DOMAIN + "/home/recruit_record/zz_money",
  // 出售房产
  SELL_HOUSE: DOMAIN + "/home/recruit_record/sell_house",
  // 合成图腾 升级图腾
  UP_TOTEM: DOMAIN + "/home/recruit_record/up_totem",
  // 随机姓名
  GET_NAME: DOMAIN + "/home/index/get_name",
  // 编辑用户 POST
  EDIT_USER: DOMAIN + "/home/user/edit_user",
  // 背包列表
  REAL_LIST: DOMAIN + "/home/user/real_list",
  // 合成家具列表
  JJ_LIST: DOMAIN + "/home/user/jj_list",
  // 激活/升级家具
  FURNITURE_UP_ONE: DOMAIN + "/home/furniture/up_one",
  // 拆家具
  FURNITURE_CHAI: DOMAIN + "/home/furniture/chai",
  // 是否领过 0.3 get
  HAS_LITTLE: DOMAIN + "/home/index/has_little",
  // 注销账号
  USER_CANCEL: DOMAIN + "/home/user/cancel",
  // 大转盘列表
  GET_TURNTABLE_LIST: DOMAIN + "/home/card/get_turntable_list",
  // 抽奖 1免费 2广告
  GET_TURNTABLE: DOMAIN + "/home/card/get_turntable",
  // 人才直聘列表
  RECRUIT_INDEX: DOMAIN + "/home/recruit/index",
  // 人才直聘招募
  RECRUIT_GET_INDEX: DOMAIN + "/home/recruit/get_recruit",
  // 猎头直聘招募
  GET_LT_RECRUIT: DOMAIN + "/home/recruit/get_lt_recruit",
  // 砸蛋
  GOLD_EGG_INDEX: DOMAIN + "/home/gold_egg/index",
  // 砸蛋  6 砸银蛋 7砸金蛋 8砸彩蛋 9砸钻石蛋 type
  GOLD_EGG_BANG_EGG: DOMAIN + "/home/gold_egg/bang_egg",
  // 金币记录
  GET_BRICK_LIST: DOMAIN + "/home/user/getBrickList",
  // 爷爷的馈赠（广告回调）  调用喷泉和爷爷之前都调一下我这个接扣 0我会返回
  GAME_WATCH_ADV: DOMAIN + "/home/game/watch_adv",
  // 兑换记录
  GOLD_RECORD: DOMAIN + "/home/gold/record",
  // 夺宝
  TREASURE_LIST: DOMAIN + "/home/treasure/list",
  // 排行榜列表
  GOLD_PAILIST: DOMAIN + "/home/gold/ph_record",
  // 排行榜列表  收益排行
  SY_PH_RECORD: DOMAIN + "/home/gold/sy_ph_record",
  // 我的钱包
  BAG_INDEX: DOMAIN + "/home/bag/index",
  // 开通钱包 is_all	是否全部
  BUG_BAG: DOMAIN + "/home/bag/buy_bag",
  // 领取钱包 id 钱包的id get
  BGA_GET_MONEY: DOMAIN + "/home/bag/get_money",
  // 收益排行榜
  BAG_RECORD: DOMAIN + "/home/bag/record",
  // 间推直推
  MX_RECORD: DOMAIN + "/home/bag/mx_record",
  // 红包界面
  ALL_MY_INDEX: DOMAIN + "/home/all_my/index",
  // 红包发放
  ALL_MY_BUY: DOMAIN + "/home/all_my/buy",
  // 红包发放
  ALL_MY_GET_BAG: DOMAIN + "/home/all_my/get_bag",
  // 广告免费
  ADVERTISEMENT_ADV_INDEX: DOMAIN + "/home/advertisement/adv_index",
  // 广告领取免费
  ADVERTISEMENT_GET_RECORD: DOMAIN + "/home/advertisement/get_record",
  // 求购列表 当前拥有数量
  HOUSE_ORDER_LOSE_NUM: DOMAIN + "/home/house_order/lose_num",
  // 拆分家具 详情
  USER_CF_MSG: DOMAIN + "/home/user/cf_msg",
  // 领取 地段天空之城 每日登录388金币
  GUIDE_GET_GOLD: DOMAIN + "/home/guide/get_gold",
  // get  邮件红点的 mail_red 1就是有红点
  GET_RED_POINT: DOMAIN + "/home/article/get_red_point",
  // 房东的接口 走位的
  LANDLORD_BLOCKING: DOMAIN + "/home/landlord/blocking",
  // get 外面列表页面
  LANDLORD_INDEX: DOMAIN + "/home/landlord/index",
  // 获得筛子
  LANDLORD_GET_SZ: DOMAIN + "/home/landlord/get_sz",
  // 获得步数
  LANDLORD_GET_BU: DOMAIN + "/home/landlord/get_bu",
  // 获奖记录 步数
  LANDLORD_RECORD: DOMAIN + "/home/landlord/record",
  // 积分兑换
  LANDLORD_JF_EXCHANGE: DOMAIN + "/home/landlord/jf_exchange",
  // task/week_index task/week_index
  TASK_WEEK_INDEX: DOMAIN + "/home/task/week_index",
  // 领取按钮，传id
  TASK_GET_WEEK_REWARD: DOMAIN + "/home/task/get_week_reward",
  // 兑换记录
  LANDLORD_JF_RECORD: DOMAIN + "/home/landlord/jf_record",
  // 推广任务
  TG_INDEX: DOMAIN + "/home/task/tg_index",
  // 公告列表
  GET_NEW_LIST: DOMAIN + "/home/user/getNewsList",
  // 公告
  GET_NEWS: DOMAIN + "/home/user/getNews",
  // 公告
  GET_NEW_ONE: DOMAIN + "/home/user/getNewOne",
  // 领取推广任务
  GET_SY_MONEY: DOMAIN + "/home/task/get_sy_money",
  // 渠道收益
  USER_GET_QUDAO: DOMAIN + "/home/user/getQuDao",
  // 渠道收益 明细
  USER_GET_QUDAO_DETAIL: DOMAIN + "/home/user/getQuDaoDetail",
  // 这个是未激活那个，Vip 0就是未激活
  USER_GET_QUDAO_USERL: DOMAIN + "/home/user/getQuDaoUser",
  // 邀请记录
  YQ_FRIEND_LIST: DOMAIN + "/home/rough/yq_friend_list",
  // 获取首页信息/werewolf/index
  WEREWOLF_INDEX: DOMAIN + "/home/werewolf/index",
  // 投入金币
  WEREWOLF_INVEST: DOMAIN + "/home/werewolf/invest",
  // 转投
  WEREWOLF_CHANGE_INVEST: DOMAIN + "/home/werewolf/change_invest",
  // 获取往期记录
  GET_WEREWOLF_LOG: DOMAIN + "/home/werewolf/get_werewolf_log",
  // 获取参与记录
  GET_WEREWOLF_JOIN_LOG: DOMAIN + "/home/werewolf/get_join_log",
  // 推广任务 邀请详情
  TASK_TG_DETAIL: DOMAIN + "/home/task/tg_detail",
  // 擂台争霸赛 获取游戏页面
  GET_MATCH: DOMAIN + "/home/ring_battle/get_match",
  // 擂台争霸赛 获取擂台争霸页面
  RING_BATTLE_INDEX: DOMAIN + "/home/ring_battle/index",
  // 广告加速器
  ADVEERTISEMENT_ADD_TIME: DOMAIN + "/home/advertisement/add_time",
  // 列表的接口 get 友情点兑换
  INTEGRAL_LIST: DOMAIN + "/home/bag/integral_list",
  // 领取的接口  post  type 1 金币 2零钱 友情点兑换 num
  INTEGRAL_EXCHANGE: DOMAIN + "/home/bag/integral_exchange",
  // 获取入围记录
  GET_FINALIST_RECORDS: DOMAIN + "/home/ring_battle/get_finalist_records",
  // 获取入围记录列表
  GET_FINALIST_RECORDS_LIST:
    DOMAIN + "/home/ring_battle/get_finalist_records_list",
  // 获取往期记录
  GET_PAST_RECORDS: DOMAIN + "/home/ring_battle/get_past_records",

  // 刘振龙
  LUCKY_NUNBER: DOMAIN + "/home/lucky_num/index",
  // 这个是投矿山列表
  MINERLIST: DOMAIN + "/home/diggings/list",
  //购买矿工
  HIRE: DOMAIN + "/home/diggings/buy_miner",
  //矿山投入矿工
  MINER: DOMAIN + "/home/diggings/save",
  //参与记录
  RECORD: DOMAIN + "/home/diggings/record",
  //往期记录
  PERIOD: DOMAIN + "/home/diggings/record_detail",
  //往期记录
  RANK: DOMAIN + "/home/diggings/rank",
  //房产详情
  HOMEDETAIL: DOMAIN + "/home/real_estate/detail",
  //整栋楼租凭购买
  LEASE: DOMAIN + "/home/real_estate/get_house",
  //整栋楼租凭购买
  ZUHOUSE: DOMAIN + "/home/real_estate/zu_house",
  //获取房间列表
  HOMELIST: DOMAIN + "/home/real_estate/house_list",
  //获取兑换码
  CODE: DOMAIN + "/home/real_estate/activation_code",
  //退租
  TUIZU: DOMAIN + "/home/real_estate/leave_house",
  //使用兑换码
  DUIHUAN: DOMAIN + "/home/real_estate/use_code",
  //世纪城拉黑租客
  BLOCKZU: DOMAIN + "/home/real_estate/no_xz_house",
  //世纪城房东续租
  XUZU: DOMAIN + "/home/real_estate/xz_house",
  //房东修改广告
  MESSAGE: DOMAIN + "/home/real_estate/send_message",
  //房东修改权限
  AUTHORITY: DOMAIN + "/home/real_estate/change_identity",
  //招财进宝列表
  BRINGLIST: DOMAIN + "/home/treasure_box/index",
  //祈福
  PRAY: DOMAIN + "/home/treasure_box/to_qf",
  //领取任务
  LINGQU: DOMAIN + "/home/task/get_task",
  //领取任务
  REWARD: DOMAIN + "/home/task/get_reward",
  //往期排行榜
  WANGQIPAI: DOMAIN + "/home/treasure_box/rank",
  //往期排行榜
  SHANGQI: DOMAIN + "/home/treasure_box/old_record",
  //奖励领取
  JIANGLI: DOMAIN + "/home/treasure_box/treasure_list",
  //奖励领取或者一键领取
  CLAIM: DOMAIN + "/home/treasure_box/get_treasure",
  //房产入口
  RUKOU: DOMAIN + "/home/real_estate/index",
  //装修的家具
  FURNIT: DOMAIN + "/home/furniture/index",
  //点击装修家具
  ZHUANGXIU: DOMAIN + "/home/furniture/up_one",
  //租金领取
  RENT: DOMAIN + "/home/rent/index",
  //领取奖励
  REWARDS: DOMAIN + "/home/rent/get_rent",
  //奖励任务
  TASK_LIST: DOMAIN + "/home/task/index",
  //领取奖励
  LINGQU_TASK: DOMAIN + "/home/task/get_reward",
  //房产出售列表
  SELLLIST: DOMAIN + "/home/auction/index",
  //房产出售
  CHUSHOUS: DOMAIN + "/home/auction/sell",
  //上架拍卖
  PAIMAI: DOMAIN + "/home/auction/auction",
  //房产拍卖列表
  PAIMAILIST: DOMAIN + "/home/auction/auction_index",
  //房产取消和冻结
  CANAEL: DOMAIN + "/home/auction/cancel",
  //房产交易列表
  TRANKLIST: DOMAIN + "/home/auction/transaction_index",
  //购买房产
  GOUMAI: DOMAIN + "/home/auction/buy",
  //竞拍详情
  JINGPAI: DOMAIN + "/home/auction/auction_detail",
  //竞拍出价
  CHUJIA: DOMAIN + "/home/auction/to_auction",
  CHUJIA: DOMAIN + "/home/auction/to_auction",
  //排行榜列表
  PAILIST: DOMAIN + "/home/real_estate/ph_list",
  //使用家具
  JIAJUSHIYONG: DOMAIN + "/home/furniture/use",
  //我的记录
  MYJILU: DOMAIN + "/home/auction/record",
  //领取金币
  JINBIL: DOMAIN + "/home/auction/get_reward",
  //挖矿山
  KUANGSHAN: DOMAIN + "/home/rough/index",
  //添加能量
  ENERGY: DOMAIN + "/home/rough/add_power",
  //出售原石
  CHUSHOU: DOMAIN + "/home/rough/sell",
  //出售列表
  CHUSHOULIST: DOMAIN + "/home/rough/record_index",
  //兑换原石列表
  DUIHUANS: DOMAIN + "/home/rough/fc_index",
  //点击兑换原石
  CLICKDUI: DOMAIN + "/home/rough/get_fc",
  //点击解锁原石
  JIESUO: DOMAIN + "/home/rough/unlock",
  //原石切割列表
  QIEGELIST: DOMAIN + "/home/rough/ys_index",
  //点击原石切割
  CLICKYUAN: DOMAIN + "/home/rough/qg_rough",
  //全服掉落
  SERVICE_DIAO: DOMAIN + "/home/rough/qf_list",
  //切割记录
  QIEGELU: DOMAIN + "/home/rough/qg_record",
  //排行
  PAIHANG_LIST: DOMAIN + "/home/rough/ph_record",
  //好友切割奖励detail
  QIEGEDETAIL: DOMAIN + "/home/rough/friend_detail",
  //好友切割奖励列表
  QIEGEDELIST: DOMAIN + "/home/rough/friend_qg",
  //好友列表
  FRIENDLIST: DOMAIN + "/home/rough/friend_list",
  //翻牌
  FANPAIJILU: DOMAIN + "/home/explore/open",
  //翻牌记录
  FANPAIJI: DOMAIN + "/home/explore/record",
  //重新开始
  CHONGXINKAISHI: DOMAIN + "/home/explore/star",
  //重新开始
  TANSUOJILU: DOMAIN + "/home/explore/ts_record",
  //矿山石领取
  KUANSSSLING: DOMAIN + "/home/diggings/get_money",
  //房产记录公示期
  GONGSHIQI: DOMAIN + "/home/auction/period",

  // 杨阳
  // 邮件列表
  YOUJIANLIST: DOMAIN + "/home/mail/index",
  // 邮件详情
  YOUJIANLISTDETAIL: DOMAIN + "/home/mail/detail",
  // 邮件领取
  YOUJIANGET: DOMAIN + "/home/mail/get_box",
  // 一键删除
  ALLDETETE: DOMAIN + "/home/mail/all_del",
  // 一键领取
  ALLGET: DOMAIN + "/home/mail/all_get",
  // 租户烦恼
  ZUHUFANNAO: DOMAIN + "/home/worried/index",
  // 租户获得钱
  GETQIANWORR: DOMAIN + "/home/worried/check",

  // 李飞
  // 夺宝详情
  TREASUREDETAIL: DOMAIN + "/home/treasure/detail",
  // 夺宝下注
  INSERT_COIN: DOMAIN + "/home/treasure/insert_coin",
  // 比赛记录 中奖名单
  RECORD_LIST: DOMAIN + "/home/treasure/record_list",
  // 参与记录 夺宝订单
  CYRECORDLIST: DOMAIN + "/home/treasure/cy_record_list",
  // 争霸赛
  ZHENGBA: DOMAIN + "/home/competition/get_competition_index",
  //争霸报名
  ZGBAOMING: DOMAIN + "/home/competition/join_competition",
  //争霸详情
  ZHENGBADETAIL: DOMAIN + "/home/competition/getMatchDetails",
  // 支付宝人脸识别
  FACEINITIALIZE: DOMAIN + "/api/face_initialize",
  // 支付宝开始认证接口
  FACE_CHECK: DOMAIN + "/api/face_check",
  // 社交管理 is_yq_ys   邀请  is_ys
  EDIT_SEER: DOMAIN + "/home/user/edit_user",
  EDIT_SEER: DOMAIN + "/home/user/edit_user",
  //获取当期幸运数字
  GETLUCKNUM: DOMAIN + "/home/lucky_num/get_lucky_nums",
  // 提交选择幸运数字
  CHOSE_NUM: DOMAIN + "/home/lucky_num/chose_num",
  // 获取中奖记录
  WINNINGLOG: DOMAIN + "/home/lucky_num/get_winning_log",
  //中奖记录领取
  LUCKNUMINFOME: DOMAIN + "/home/lucky_num/income",
  //能量记录
  PROWRECOL: DOMAIN + "/home/user/getActiveList",
  //房东进自己房子
  FNAGHOMEISJIN: DOMAIN + "/home/real_estate/return_house",
  //招财进宝第一个
  ZHAOCAIJNBAO: DOMAIN + "/home/treasure_box/get_gold",
  //领取能量
  LINGQUPROW: DOMAIN + "/home/real_estate/get_power",

  // 230628 -lifei
  // 获取游戏信息
  GETMATCH: DOMAIN + "/home/competition/get_match",
  //room_id attacked_uid 攻击接口
  ATTACK: DOMAIN + "/home/competition/attack",
  // 获取参与记录
  GETJOINLOG: DOMAIN + "/home/competition/get_join_log",

  //招财进宝记录
  ZHAOJINBAO: DOMAIN + "/home/treasure_box/record",
  //卸下家具
  XIEXIAJIA: DOMAIN + "/home/furniture/xie",
};

// 判断用户是否登录或者登录是否有效
function checkLogin() {
  var token = getCookie("token");
  if (!token) location.href = LOGIN_PAGE;
}

/**
 * 设置cookie
 * @param {String} key 键名
 * @param {String} value 键值
 * @param {Number} expire 有效期(秒)
 */
function setCookie(key, value, expire = 0) {
  var now = new Date();
  var nt = now.getTime();
  var ep = new Date(nt + expire * 1000);
  // 编码兼容中文
  value = encodeURIComponent(value);
  document.cookie = key + "=" + value + "; path=/; expires=" + ep;
}
/**
 * 读取cookie
 * @param {String} key 键名
 */
function getCookie(key) {
  var arr1 = document.cookie.split("; ");
  for (var i = 0; i < arr1.length; i++) {
    var arr2 = arr1[i].split("=");
    if (arr2[0] == key) {
      return decodeURIComponent(arr2[1]);
    }
  }
  return "";
}
/**
 * [removeCookie 移除cookie]
 */
function removeCookie(key) {
  setCookie(key, "", -1); // 把cookie设置为过期
  localStorage.removeItem(key);
}
//清除所有cookie函数
function clearAllCookie() {
  var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
  if (keys) {
    for (let i = 0; i < keys.length; i++) {
      setCookie(keys[i], "", -1);
    }
  }
}

/**
 * @description 显示一个提示
 * @param {String} str 提示文字
 * @param {Number} n 显示时长
 * @param {Number} f 动画帧率
 */
function openTips(str, n = 2000, f = 25) {
  let t = new Date();
  let d = document.createElement("div");
  d.className = "tips";
  d.innerHTML = "<span>" + str + "</span>";
  document.body.appendChild(d);
  setTimeout(() => {
    let o = 0.95;
    let s = setInterval(() => {
      o -= 0.05;
      if (o < 0) {
        clearInterval(s);
        document.body.removeChild(d);
      } else {
        d.style.opacity = o;
      }
    }, f);
  }, n);
}

// 复制文本内容
function copy(str) {
  var oInput = document.createElement("input");
  oInput.value = str;
  document.body.appendChild(oInput);
  oInput.select(); // 选择对象
  var ec = document.execCommand("Copy"); // 执行浏览器复制命令
  oInput.style.display = "none";
  return ec;
}

/**
 * 获取用户信息
 * @param {Function} cb 回调函数
 */
function getUserInfo(cb) {
  let token = getCookie("token");
  let userid = getCookie("userid");
  if (!token) {
    openTips("暂未登录，请先登录");
    setTimeout(function () {
      location.replace(LOGIN_PAGE);
    }, 1000);
    return false;
  }
  ajax({
    method: "GET",
    url: API_PATH.USER_INFO,
    header: {
      // 'phoenix-token': token,
      // 'phoenix-id': userid,
      Authorization: token,
    },
    success: (res) => {
      // console.log(res);return;
      if (res.code != 1) {
        openTips("登录失效，请重新登录");
        setTimeout(function () {
          location.replace(LOGIN_PAGE);
        }, 1000);
        return;
      }
      // 存储必要的用户信息
      setInfo(res.data);
      // debugger
      cb && cb(res.data);
    },
    error: (err) => {
      // alert(err.status);
    },
  });

  function setInfo(data) {
    var dt = 365 * 24 * 60 * 60;
    setCookie("userid", data.id, dt);
    setCookie("mobile", data.mobile, dt);
    setCookie("nickname", data.nickname, dt);
    setCookie("is_pay", data.is_pay, dt);
    setCookie("level", data.level, dt);
    setCookie("lmb", data.lmb, dt);
    setCookie("money", data.user_money, dt);
    setCookie("is_check", data.is_check, dt);
    setCookie("invite_code", data.invite_code, dt);
    setCookie("alipay_name", data.info.alipay_name, dt);
    setCookie("alipay_account", data.info.alipay_account, dt);
    setCookie("type", data.type, dt);
    setCookie("level", data.level, dt);
    setCookie("direct", data.direct, dt);
    setCookie("p_mobile", data.p_mobile, dt);
    setCookie("p_level", data.p_level, dt);
    setCookie("p_mobile", data.p_mobile, dt);
    setCookie("p_wx", data.p_wx, dt);
    setCookie("p_qq", data.p_qq, dt);
    setCookie("p_qqq", data.p_qqq, dt);
    setCookie("p_nickname", data.p_nickname, dt);
    setCookie("qq", data.qq, dt);
    setCookie("qqq", data.qqq, dt);
    setCookie("wx", data.wx, dt);
    setCookie("phone", data.phone, dt);
    setCookie("vip", data.vip, dt);
    setItem("info", data.info);
  }
}

function goBack() {
  history.back();
}

function navgateTo(str) {
  if (str) location.href = str;
}

// 存储数据到localStorage 支持对象存储
function setItem(k, v) {
  localStorage.setItem(k, JSON.stringify(v));
}
// 读取local storage 数据
function getItem(k) {
  return JSON.parse(localStorage.getItem(k));
}

/**
 * @description  HTML元素节点选择器
 * @author kevinE kevin-e-e#foxmail
 * @version v2.0 2022-2-9 10:51:30
 * @param {String} str 需要选择的标签，类，ID名称
 * @return {HTMLElement, NodeList} 选中的元素或元素数组
 */
function $(str) {
  let arr = str.split(" ");
  if (arr.length == 1) {
    return getElement(str);
  } else {
    // 符合条件的最终元素
    let rs = [];
    // 所有层级选择元素
    let as = [];
    for (let i = arr.length - 1; i >= 0; i--) {
      as.push(getElement(arr[i]));
    }

    // 判断 高层级元素 是否是 低层级元素 的父元素
    for (let i = as.length - 1; i > 0; i--) {
      // 低层级元素
      let cs = as[i - 1];
      // 高层级元素
      let ps = as[i].localName == "object" ? as[i] : [as[i]];
      rs = getMate(cs, ps);
    }
    return rs;

    /**
     * @description 获取 父子元素匹配 的 子元素
     * @param {NodeList} childs 子节点数组
     * @param {NodeList} parents 父节点数组
     * @return {NodeList} 匹配的子元素数组
     */
    function getMate(childs, parents) {
      let arr = [];
      for (let i = 0; i < childs.length; i++) {
        for (let j = 0; j < parents.length; j++) {
          if (isChild(childs[i], parents[j])) arr.push(childs[i]);
        }
      }
      return arr;
    }
  }

  /**
   * @description 判断 元素 是否是 目标元素 子节点
   * @param {HTMLElement} node
   * @param {HTMLElement} target
   */
  function isChild(node, target) {
    let result = false;
    let nps = getParentNodes(node);
    return nps.includes(target);
  }

  /**
   * @description 获取元素所有父节点
   * @param {HTMLElement} node
   * @return {NodeList} 元素所有父节点
   */
  function getParentNodes(node) {
    let arr = [];
    getParent(node);

    function getParent(node) {
      let pn = node.parentNode;
      if (pn != document.body) {
        arr.push(pn);
        return getParent(pn);
      } else arr.push(pn);
    }
    return arr;
  }

  // 获取单项元素节点
  function getElement(str) {
    function getByTage(str) {
      return document.getElementsByTagName(str);
    }

    function getByClass(str) {
      return document.getElementsByClassName(str);
    }

    function getById(str) {
      return document.getElementById(str);
    }
    let tar = /[#\.]/.test(str) ? str.substr(1) : str;
    if (str.indexOf(".") === 0) return getByClass(tar);
    else if (str.indexOf("#") === 0) return getById(tar);
    else return getByTage(tar);
  }
}

// 2021-5-19 kevin 获取设备类型
function getClientType() {
  let ua = navigator.userAgent.toLowerCase();
  if (ua.indexOf("iphone") > 0 || ua.indexOf("ipad") > 0) {
    // return "iphone";
    return "ios";
  } else if (ua.indexOf("android") > 0) {
    return "android";
  } else if (ua.indexOf("windows") > 0) {
    return "windows";
  } else {
    return "other";
  }
}

// 获取URL参数 2021-5-20
function getUrlParam(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
  var r = window.location.search.substr(1).match(reg); //匹配目标参数
  if (r != null) return unescape(r[2]);
  return null; //返回参数值
}

/**
 * 获取JSON配置文件
 * by kevinE 2021-9-25 15:04:18
 * @param {URL} url 请求文件地址
 * @param {Function} cb 成功回调
 * @return {JSON} json json对象
 */
async function getConfig(url, cb) {
  const res = await fetch(url);
  const json = await res.json();
  cb && cb(json);
  return json;
}

/**
 * @description 获取游戏专属链接
 * @param {Number} uid 用户ID
 * @param {Number} gid 游戏ID
 * @param {Function} cb 获取成功回调函数
 */

function getGameLink(uid, gid, token, mobile, cb) {
  // console.log(getCookie('token'));
  ajax({
    url: API_PATH.GET_GAME_LINK,
    data: {
      id: uid,
      gid: GAME_ID,
      token: getCookie("token"),
      mobile: getCookie("mobile"),
    },
    success: (res) => {
      // console.log(res);
      if (res.code == 1) {
        cb && cb(res.data);
      }
    },
  });
}

setStatusBar();

function setStatusBar() {
  document.addEventListener("plusready", function () {
    // 返回键逻辑
    plus.navigator.setStatusBarBackground("#000");
    plus.navigator.setStatusBarStyle("light");
    var webview = plus.webview.currentWebview();
    var first = null;
    var list = ["home", "check", "abilityPerson", "makeMoney", "market", "my"];
    plus.key.addEventListener("backbutton", function () {
      webview.canBack(function (e) {
        if (
          ~location.pathname.indexOf("home") ||
          ~location.pathname.indexOf("leyuan") ||
          ~location.pathname.indexOf("abilityPerson") ||
          ~location.pathname.indexOf("makeMoney") ||
          ~location.pathname.indexOf("market") ||
          ~location.pathname.indexOf("my")
        ) {
          if (!first) {
            first = new Date().getTime();
            plus.nativeUI.toast("再按一次退出应用", {
              verticalAlign: "bottom",
            });
            setTimeout(function () {
              first = null;
            }, 1000);
          } else {
            if (new Date().getTime() - first < 1500) {
              plus.runtime.quit();
            }
          }
        } else webview.back();
      });
    });
  });
}

/**
 * 数字对象拓展 数字缩短长度
 * @author kevinE kevin-e-e@foxmail.com
 * @version v1.0 2021-11-5 09:33:25
 * @param {Number} prec 保留小数位
 * @param {Number} type 显示模式 1中文,2英文
 */
Number.prototype.format = function (type = 1) {
  let prec = 2;
  let _this = parseFloat(this);
  if (_this > 1e8) {
    if (type === 1) {
      if (_this > 1e10) {
        return (_this / 1e8).toFixed(1) + "亿";
      } else return (_this / 1e8).toFixed(prec) + "亿";
    } else return (_this / 1e8).toFixed(prec) + "E";
  }
  if (_this > 1e4) {
    if (type === 1) {
      if (_this > 1e6) return (_this / 1e4).toFixed(1) + "万";
      else return (_this / 1e4).toFixed(prec) + "万";
    } else return (_this / 1e4).toFixed(prec) + "W";
  } else return parseFloat(_this).toFixed(prec);
};

/**
 * 日期对象拓展 日期格式化
 * @author kevinE kevin-e-e@foxmail.com
 * @version v1.0 2021-9-25 14:39:43
 * @param {String} format 格式字符串，支持大写字母Y M D H I S C，其他字符原样输出
 * @param {String} date [日期字符]，默认使用当前时间
 */
Date.prototype.format = function (format, date) {
  const fm = ["Y", "M", "D", "H", "I", "S", "C"];
  let Y,
    M,
    D,
    H,
    I,
    S,
    C,
    d,
    str = "";
  if (date) d = new Date(date);
  else d = new Date();
  let _Y = d.getFullYear();
  let _M = d.getMonth() + 1;
  _M = _M < 10 ? "0" + _M : _M;
  let _D = d.getDate();
  _D = _D < 10 ? "0" + _D : _D;
  let _H = d.getHours();
  _H = _H < 10 ? "0" + _H : _H;
  let _I = d.getMinutes();
  _I = _I < 10 ? "0" + _I : _I;
  let _S = d.getSeconds();
  _S = _S < 10 ? "0" + _S : _S;
  let _C = d.getMilliseconds();
  _C = _C < 100 ? (_C < 10 ? "00" + _C : "0" + _C) : _C;
  for (var i = 0; i < format.length; i++) {
    let fi = format[i];
    if (fm.indexOf(fi) >= 0) str += eval("_" + fi);
    else str += format[i];
  }
  return str;
};

/**
 * 对象数组拓展 数组按指定属性键值排序
 * @author kevinE kevin-e-e@foxmail.com
 * @version v1.0 2022-2-27 15:20:09
 * @param {String} key 指定的属性键名
 */
Array.prototype.keySort = function (key) {
  let that = this;
  for (let i = 0; i < that.length - 1; i++) {
    for (let j = 0; j < that.length - 1; j++) {
      if (parseFloat(that[j][key]) > parseFloat(that[j + 1][key])) {
        let temp = that[j];
        that[j] = that[j + 1];
        that[j + 1] = temp;
      }
    }
  }
  return this;
};

/**
 * 对象数组拓展 数组按指定属性键值排序
 * @author kevinE kevin-e-e@foxmail.com
 * @version v1.0 2022-3-2 11:49:27
 * @param {String} key 指定的属性键名
 * @param {String} val 指定的属性值
 */
Array.prototype.given = function (key, val) {
  let obj = null;
  let that = this;
  for (let i = 0; i < that.length; i++) {
    if (that[i][key] == val) return that[i];
  }
  return obj;
};

/**
 * 发送ajax请求
 * @author kevinE kevin-e-e@foxmail.com
 * @version v1.0 2021-9-25 15:00:30
 * @param {JSON} cfg xhr配置
 * @param {URLString} cfg.url 请求路径
 * @param {String} cfg.method 请求方式[GET, POST]
 * @param {JSON} cfg.header 请求头
 * @param {JSON} cfg.data 请求参数
 * @param {Function} cfg.success 成功回调
 * @param {Boolean} cfg.isAsync 是否异步
 * @param {Function} cfg.error 错误回调
 */
function ajax({
  url,
  method = "GET",
  header,
  data,
  success = null,
  isAsync = true,
  error = null,
}) {
  ver = getCookie("xhr.ver") || new Date().format("MDHIS");
  let _data = "";
  for (let k in data) {
    _data += "&" + k + "=" + data[k];
  }
  let xhr = new XMLHttpRequest();
  if (method === "GET" || method == "get") url = url + "?v=" + ver + _data;
  else url = url + "?v=" + ver;
  xhr.open(method, url, isAsync);
  if (method === "POST" || method === "post")
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  if (header) {
    for (let key in header) {
      xhr.setRequestHeader(key, header[key]);
    }
  }
  xhr.onreadystatechange = function () {
    if (xhr.readyState == 4 && xhr.status === 200) {
      let res = JSON.parse(xhr.responseText);
      success && success(res);
    } else if (xhr.readyState == 4 && xhr.status !== 200) {
      error && error(xhr);
    }
  };
  xhr.send(_data);
}

/**
 * 缓存控制器 静态HTML版本管理 不能真正清除缓存文件
 * 工作原理是通过控制版本号 绕过缓存机制实现强制刷新页面
 * @author kevinE kevin-e-e@foxmail.com
 * @version v1.0 2021-9-25 14:43:41
 * @example 在需要做版本控制的页面执行该函数 使用cleanCache函数清除缓存更新版本
 */
function ctrlCache() {
  // 缓存版本键名
  let vk = PREFIX + "-ver";
  // 缓存版本[数字]
  let vv = getItem(vk) || new Date().format("YMDHIS");
  // 缓存文件键名
  let ck = PREFIX + "-cache-" + vv;
  // 缓存文件[数组]
  let cf = getItem(ck) || [];
  // 当前页面路径
  let hf = location.origin + location.pathname;
  // 当前页面不在缓存中
  if (cf.indexOf(hf) < 0) {
    // 将当前路径存入缓存
    console.log(hf);
    cf.push(hf);
    // 添加版本号后重新加载
    let _hf = hf + "?v=" + vv;
    // 存储缓存版本
    setItem(vk, vv);
    // 存储缓存文件名
    setItem(ck, cf);
    location.replace(_hf);
    return false;
  }
}
// 清空缓存[强制刷新]
function cleanCache() {
  // 缓存版本键名
  let vk = PREFIX + "-ver";
  // 获取已有版本信息
  let _vv = getItem(vk);
  // 缓存文件键名
  let ck = PREFIX + "-cache-" + _vv;
  // 清除已有缓存文件
  localStorage.removeItem(ck);
  // 缓存新版本号
  let vv = new Date().format("YMDHIS");
  // 存储新的缓存版本
  setItem(vk, vv);
  // 查询最新版本 判断是否更新成功
  let nv = getItem(vk);
  // 返回操作结果
  return vv == nv;
}

// 打开模态框
function openMdl(id) {
  id.style.display = "block";
}

// 关闭模态框
function closeMdl(id) {
  id.style.display = "none";
}

let lx_reward = $("#modal-offlineRewards");
let close_offlineRewards = $("#close-offlineRewards");
let rewardag = $("#rewardag");

function regTime() {
  let token = getCookie("token");
  ajax({
    url: API_PATH.REG_TIME,
    method: "GET",
    header: {
      Authorization: token,
    },
    success: (res) => {
      if (res.code == 1) {
        // openTips(res.msg);
        sessionStorage.setItem("key", 1);
        rewardag.innerHTML = res.data;
        openMdl(lx_reward);
      }
      leaveTime();
      setInterval(() => {
        leaveTime();
      }, 600000);
    },
  });
}
// console.log(+new Date());
function leaveTime() {
  let token = getCookie("token");
  ajax({
    url: API_PATH.LEAVE_TIME,
    method: "GET",
    header: {
      Authorization: token,
    },
    success: (res) => {
      // if (res.code == 1) {
      // 	openTips(res.msg);
      // }
      sessionStorage.setItem("keytime", +new Date());
    },
  });
}

let homemask = sessionStorage.getItem("key");

// console.log(homemask != null && !homemask);
if (homemask != null && !homemask) {
  regTime();
} else {
  let now = +new Date();
  let old = sessionStorage.getItem("keytime");
  if (parseInt(now) >= parseInt(595000) + parseInt(old)) {
    leaveTime();
    setInterval(() => {
      leaveTime();
    }, 600000);
  }
}

//倒计时效果
function getCountTime(time) {
  const now = +new Date();
  const last = time * 1000;
  // console.log(now,last);
  // 得到剩余时间戳
  const count = (last - now) / 1000;
  // 时
  let h = parseInt((count / 60 / 60) % 24);
  h = h < 10 ? "0" + h : h;
  // 分
  let m = parseInt((count / 60) % 60);
  m = m < 10 ? "0" + m : m;
  // 秒
  let s = parseInt(count % 60);
  s = s < 10 ? "0" + s : s;
  // h = h.split('-')[1]
  // m = m.split('-')[1]
  // s = s.split('-')[1]
  if (h < 0 && (m < 0) & (s < 0)) {
    let str = "到时间了";
    return str;
  } else {
    // console.log(h,m,s);
    return `${h}:${m}:${s}`;
  }
}
//倒计时效果
function getCountMiao(time) {
  const now = +new Date();
  const last = time * 1000 + +now;
  //   console.log(last, now);
  // console.log(now,last);
  // 得到剩余时间戳
  const count = (last - now) / 1000;
  // 时
  let day = parseInt(count / 60 / 60 / 24);
  day = day < 10 ? "0" + day : day;
  let h = parseInt((count / 60 / 60) % 24);
  h = h < 10 ? "0" + h : h;
  // 分
  let m = parseInt((count / 60) % 60);
  m = m < 10 ? "0" + m : m;
  // 秒
  let s = parseInt(count % 60);
  s = s < 10 ? "0" + s : s;
  if (h < 0 && (m < 0) & (s < 0)) {
    let str = "到时间了";
    return str;
  } else {
    // console.log(h,m,s);
    return `${h}:${m}:${s}`;
  }
}
//倒计时效果
function getCountTimeDay(time) {
  const now = +new Date();
  const last = time * 1000;
  // 得到剩余时间戳
  const count = (last - now) / 1000;
  let day = parseInt(count / 60 / 60 / 24);
  day = day < 10 ? "0" + day : day;
  // 时
  let h = parseInt((count / 60 / 60) % 24);
  h = h < 10 ? "0" + h : h;
  // 分
  let m = parseInt((count / 60) % 60);
  m = m < 10 ? "0" + m : m;
  // 秒
  let s = parseInt(count % 60);
  s = s < 10 ? "0" + s : s;

  return `${day}天${h}:${m}:${s}`;
}

//倒计时效果
function getCountTimeMin(time) {
  const now = +new Date();
  const last = time * 1000;
  // 得到剩余时间戳
  const count = (last - now) / 1000;
  let day = parseInt(count / 60 / 60 / 24);
  day = day < 10 ? "0" + day : day;
  // 时
  let h = parseInt((count / 60 / 60) % 24);
  h = h < 10 ? "0" + h : h;
  // 分
  let m = parseInt((count / 60) % 60);
  m = m < 10 ? "0" + m : m;
  // 秒
  let s = parseInt(count % 60);
  s = s < 10 ? "0" + s : s;

  if ((m <= 0) & (s <= 0)) {
    let str = "";
    return str;
  } else {
    return `${m}:${s}`;
  }
}

//倒计时效果
function getCountTimeMiao(time) {
  const now = +new Date();
  const last = time;
  // 得到剩余时间戳
  const count = (last - now) / 1000;
  let day = parseInt(count / 60 / 60 / 24);
  day = day < 10 ? "0" + day : day;
  // 时
  let h = parseInt((count / 60 / 60) % 24);
  h = h < 10 ? "0" + h : h;
  // 分
  let m = parseInt((count / 60) % 60);
  m = m < 10 ? "0" + m : m;
  // 秒
  let s = parseInt(count % 60);
  s = s < 10 ? "0" + s : s;

  if ((m <= 0) & (s <= 0)) {
    let str = "";
    return str;
  } else {
    return `${m}:${s}`;
  }
}
